# 定义项目名称，可根据实际情况修改
$PROJECT_NAME = "lightshare"

# 定义目标平台和架构
$PLATFORMS = @(
    "windows/amd64",
    "windows/386",
    "linux/amd64",
    "linux/386",
    "linux/arm64",
    "darwin/amd64",
    "darwin/arm64"
)

# 创建输出目录
New-Item -ItemType Directory -Force -Path bin | Out-Null

# 遍历平台和架构列表进行编译
foreach ($PLATFORM in $PLATFORMS) {
    $parts = $PLATFORM -split "/"
    $OS = $parts[0]
    $ARCH = $parts[1]
    Write-Host "正在编译 $OS $ARCH 版本..."
    $OUTPUT_NAME = "$PROJECT_NAME-$OS-$ARCH"
    if ($OS -eq "windows") {
        $OUTPUT_NAME = "$OUTPUT_NAME.exe"
    }
    $env:GOOS = $OS
    $env:GOARCH = $ARCH
    go build -ldflags "-s -w" -o "bin/$OUTPUT_NAME"
    if ($LASTEXITCODE -eq 0) {
        Write-Host "$OS $ARCH 版本编译成功，输出文件: bin/$OUTPUT_NAME"
    } else {
        Write-Host "$OS $ARCH 版本编译失败"
    }
}

Write-Host "编译完成"
